import request from "@/utils/request";

// 获取图书列表（分页、分类、关键词）
export function fetchBooks(params: {
  page?: number;
  size?: number;
  category_id?: number | string;
  keyword?: string;
} = {}) {
  return request({
    url: '/books',
    method: 'get',
    params
  })
}

// 获取图书详情
export function fetchBookDetail(bookId: number | string) {
  return request({
    url: `/books/${bookId}`,
    method: 'get'
  })
}

// 获取图书评价列表
export function fetchBookReviews(bookId: number | string, params: { page?: number; size?: number } = {}) {
  return request({
    url: `/books/${bookId}/reviews`,
    method: 'get',
    params
  })
}

// 添加图书评价
export function addBookReview(bookId: number | string, data: { comment: string; rating: number }) {
  return request({
    url: `/books/${bookId}/reviews`,
    method: 'post',
    data
  })
}

// 购物车
export function addToCart(data: { book_id: number | string; quantity: number }) {
  return request({
    url: '/cart/items',
    method: 'post',
    data
  })
}

export function fetchCart() {
  return request({
    url: '/cart',
    method: 'get'
  })
}